/*
 * 线索查询
 * @author 孙令浩
 * @time 2018/12/03
 * @since 1.0.0
 * */
// React基础组件
import React from 'react'
// dva 连接组件 - 连接route和model
import { connect } from 'dva'
// 引入antd的组件
import { Form, Select, Input, DatePicker, Button } from 'antd'
import moment from 'moment';
const { RangePicker } = DatePicker;
const dateFormat = 'YYYY/MM/DD';
//导入路由组件，用于跳转等
import { Link, hashHistory } from 'dva/router'
// 导入项目全局配置文件
import config from 'config/config'

// 引入model取值工具方法
import { mapStateToProps } from 'utils/view_utils'
// 当前组件样式
import styles from './threadListStyle.less'
//引用listPage
import ListPage from 'widget/PageTmpl/ListPage'
import cx from 'classnames'

const Option = Select.Option;
/**
 * description 路由视图及事件处理
 * dispatch 分发到models中的effects对应事件名
 * model 用于获取models中state定义的数据
 * form 表单对象
 */

const infoListAdminView = function ({ dispatch, model, form }) {
  // 表单的子函数
  const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
  // 取出model对象，命名空间
  const { modelObj, namespace } = model
  // let { areaList } = modelObj;
  // console.warn(areaList, 'area');
  // modelObj.xxx获取model中状态机的值

  // 资讯详情页跳转
  // function detailSkip(id, name,mobile, date) {
    function detailSkip(id) {
    console.log("id："+id)
    hashHistory.push({
      pathname: '/home/threadAdmin/threadDetail',
      query: { clueId: id}
    });
    
  }
  function recommendClientsList(referrerName,referrerMobile){
    // console.log("data:"+referrerName);
    hashHistory.push({
      pathname: '/home/threadAdmin/recommendClientsList',
      query: {referrerName,referrerMobile}
    });
  }
  let pageProps = {
    // ---------- 界面部分 ----------
    "ui": {
      // 页面接口地址
      "api_url": "admin/user/queryClue",
      // 接口方式
      "method": "POST",
      "app": "",
      // 接口参数
      "params": "",
      // 模拟数据 - 用于开发需要，若填充了上面的api_url之后，请将此项设置为null
      // "mockData": mockData,
      "mockData": null,
      // 查询栏
      "search_bar": {
        "fields": [
         
          {
            en_name: 'name',
            zh_name: '姓名',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          {
            en_name: 'mobile',
            zh_name: '手机号码',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
        ],
        searchHandler: () => { // 自定义搜索按钮回调函数，点击搜索时触发
          console.log('search click')
        },
        resetHandler: () => { // 自定义重置按钮回调函数，点击重置时触发
          console.log('reset click')
        },
        searchCallback: params => { // 自定义搜索完成后的后调函数, 搜索完成后触发, 并将本次搜索的参数传入
          console.log('search finish', params)
        },
        pasteTargetList: [  // 列表组件中将输入框的en_name作为默认id(也可以通过id另外设置)
          'carName',  // 将需要粘贴事件拦截的输入框id以数组的形式传入, 该参数对应PasteFromClipboard组件的targetList参数
        ]
      },
      // 数据表格
      "table":
      {
        "status_params": "status=0",
        "status_text": "全部",
        // 表头字段列表
        "scroll": { x: 1000 },
        "fields": [
          {
            "en_name": "name",
            "zh_name": "姓名",
          },
          {
            "en_name": "mobile",
            "zh_name": "手机号",
            width:130,
          },
          {
            "en_name": "productName",
            "zh_name": "推荐楼盘",
          },
          {
            "en_name": "typeName",
            "zh_name": "客户类型",
          },
          {
            "en_name": "referrerName",
            "zh_name": "推荐人姓名",
            render: (a, item, index, d, e, f) => {
              return (
                <span>
                  <a style={{color:'#0877FD'}}  onClick={() => recommendClientsList(item.referrerName,item.referrerMobile)}>{item.referrerName}</a>
                </span>
              )
            },
          },
          {
            "en_name": "referrerMobile",
            "zh_name": "推荐人手机",
            width:130,
          },
          {
            "en_name": "edit",
            "zh_name": "操作",
            render: (a, item, index, d, e, f) => {
              return (
                <span>
                  <a onClick={() => detailSkip(item.clueId)}>用户详情</a>
                </span>
              )
            },
          }
        ]
      },
    },
  }
  if (!!modelObj.biz) {
    pageProps.biz = modelObj.biz
    pageProps.biz.syncBackCbf = (biz) => {
      console.log(biz)
      dispatch({
        type: `${namespace}/updateStore`,
        payload: { biz }
      })
    }
  }
  return (
    <div className={cx('pageLayout')}>
      <ListPage pageProps={pageProps} />
    </div>
  )
}

// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(infoListAdminView))
